package com.explorex.infra.puma.gateway.netty.rrmp.codec;

import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;

/**
 * @author: JacceYang
 * @createTime: 2022/09/06 10:15 上午
 * @description: 自定义消息体头部信息
 */
@Data
public class MessageHeader {

    public static final int HEADER_LENGTH = 12;
    public static final int PING_LENGTH = 3;
    public static final byte MAGIC = 0x6;

    private byte magic = MAGIC;
    private int business;
    private byte encryptType = (byte) 0x0;
    private byte protocolVersion = (byte) 0x1;
    private byte qos = (byte) 0x1;
    private byte reservedBits = (byte) 0x0;
    private int bodyLength;
    private byte keyCheck;
    private byte[] bodyCheck = new byte[]{0x0, 0x0, 0x0};

    public MessageHeader(int business, byte keyCheck, int bodyLength, byte[] bodyCheck, byte protocolVersion) {
        this.business = business;
        this.bodyLength = bodyLength;
        this.keyCheck = keyCheck;
        this.bodyCheck = bodyCheck;
        this.protocolVersion=protocolVersion;
    }

    public MessageHeader() {
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}
